from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Base():
    # 初始化驱动
    def __init__(self,driver:WebDriver):
        self.driver = driver
    # 打开网址的方法
    def open_url(self,url):
        self.driver.get(url)

    # 定位元素方法
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,10,0.5).until(lambda driver:driver.find_element(*loc).is_displayed())
            return self.driver.find_element(*loc)
        except Exception as e:
            print(e)

    # 点击方法
    def click(self,loc):
        self.find_element(loc).click()

    # 输入方法
    def send_keys(self,loc,info):
        # 先清除
        self.find_element(loc).clear()
        # 再输入
        self.find_element(loc).send_keys(info)

    # 获取文本方法
    def get_text(self,loc):
        return self.find_element(loc).text

    # 滑动到底部方法
    def scroll_height(self):
        self.driver.execute_script('window.scrollTo(0,document.body.scrollHeight)')